/*
    Project: OCMF (Operant Chamber Management Framework)
    Version: 1.0
    Author: Copyright (C) 2010, Samuel Delaney & Andrew Harvey
    Licence:
        This file is part of OCMF.

            OCMF is free software: you can redistribute it and/or modify
            it under the terms of the GNU General Public License as published by
            the Free Software Foundation, either version 3 of the License, or
            (at your option) any later version.

            OCMF is distributed in the hope that it will be useful,
            but WITHOUT ANY WARRANTY; without even the implied warranty of
            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
            GNU General Public License for more details.

            You should have received a copy of the GNU General Public License
            along with OCMF.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ACTIONCOLLECTION_H
#define ACTIONCOLLECTION_H

#include <QVector>
#include <QObject>

#include "Buzzer.h"
#include "Counter.h"
#include "Delay.h"
#include "Food.h"
#include "GoTo.h"
#include "HouseLight.h"
#include "Prl.h"
#include "Stop.h"
#include "serverconfig.h"

class Trial;

class ActionCollection : public Action, public QObject
{
private:
    Trial * ownerTrial;
public:
    ActionCollection(Trial * trial)
    {
        ownerTrial = trial;
    }

    ActionCollection(QDomNode actionCollectionElement, Action * parentAction)
    {
        //get the child nodes of the passed node
        QDomNodeList actionElements = actionCollectionElement.childNodes();

        //iterate over each child
        for(int i = 0; i < actionElements.count(); i++)
        {
            //get and alias the tag name to determine the action type
            QString tagName = actionElements.at(i).toElement().tagName();

            if(tagName == "Buzzer")
                Actions.push_back(new Buzzer(actionElements.at(i).toElement(), (Action*)this));
            else if(tagName == "Counter")
                Actions.push_back(new Counter(actionElements.at(i).toElement(), (Action*)this));
            else if(tagName == "Delay")
                Actions.push_back(new Delay(actionElements.at(i).toElement(), (Action*)this));
            else if(tagName == "Food")
                Actions.push_back(new Food(actionElements.at(i).toElement(), (Action*)this));
            else if(tagName == "GoTo")
                Actions.push_back(new GoTo(actionElements.at(i).toElement(), (Action*)this));
            else if(tagName == "HouseLight")
                Actions.push_back(new HouseLight(actionElements.at(i).toElement(), (Action*)this));
            else if(tagName == "Prl")
                Actions.push_back(new Prl(actionElements.at(i).toElement(), (Action*)this));
            else if(tagName == "Stop")
                Actions.push_back(new Stop(actionElements.at(i).toElement(), (Action*)this));
        }

        currentActionIndex = 0;
    }

    //implemented functions from action class
    void Do()
    {
        //iterate over each action in the vector
        for(currentActionIndex = 0; currentActionIndex < Actions.count(); currentActionIndex++)
            Actions[currentActionIndex]->Do();
    }

    QDomElement ToResultXml()
    {
        return QDomElement();
    }

    Trial * OwnerTrial()
    {
        return ownerTrial;
    }

    int currentActionIndex;

    QVector<Action *> Actions;
};

#endif // ACTIONCOLLECTION_H
